/*
XBaseTools
Copyright (C) 2008 Matthew Perry

This library/program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This libary/program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;

namespace SourceTools.IO
{
	/// <summary>
	/// Search path type
	/// </summary>
	public enum SearchPathType
	{
		/// <summary>
		/// Game entry
		/// </summary>
		GamePath,
		/// <summary>
		/// TestPathID entry
		/// </summary>
		TestPath
	}
	
	/// <summary>
	/// A search path for Source games
	/// </summary>
	public struct SearchPath : IEquatable<SearchPath>
	{
		/// <summary>
		/// The type of search path
		/// </summary>
		public SearchPathType Type;
		
		/// <summary>
		/// The path
		/// </summary>
		public string Path;
		
		/// <summary>
		/// Creates a new SearchPath
		/// </summary>
		/// <param name="Type">The type of search path</param>
		/// <param name="Path">The path of the search path</param>
		public SearchPath(SearchPathType Type, string Path)
		{
			this.Type = Type;
			this.Path = Path;
		}
		
		#region Equals and GetHashCode implementation
		// The code in this region is useful if you want to use this structure in collections.
		// If you don't need it, you can just remove the region and the ": IEquatable<SearchPath>" declaration.
		
		/// <summary>
		/// Equals
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public override bool Equals(object obj)
		{
			if (obj is SearchPath)
				return Equals((SearchPath)obj); // use Equals method below
			else
				return false;
		}
		
		/// <summary>
		/// Equals
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public bool Equals(SearchPath other)
		{
			// add comparisions for all members here
			return this.Type == other.Type && this.Path == other.Path;
		}
		
		/// <summary>
		/// Xor'ed hashcodes
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			// combine the hash codes of all members here (e.g. with XOR operator ^)
			return Type.GetHashCode() ^ Path.GetHashCode();
		}
		
		/// <summary>
		/// Equals operator
		/// </summary>
		/// <param name="lhs"></param>
		/// <param name="rhs"></param>
		/// <returns></returns>
		public static bool operator ==(SearchPath lhs, SearchPath rhs)
		{
			return lhs.Equals(rhs);
		}
		
		/// <summary>
		/// Inequal operator
		/// </summary>
		/// <param name="lhs"></param>
		/// <param name="rhs"></param>
		/// <returns></returns>
		public static bool operator !=(SearchPath lhs, SearchPath rhs)
		{
			return !(lhs.Equals(rhs)); // use operator == and negate result
		}
		#endregion
	}
}
